package shujujiegou;

import java.util.ArrayList;

import java.util.List;
import java.util.Random;

class TestRBTree {

    //37152
    public static void main(String[] args) {
//		int[] in = {25,80,28,33,82,62,73,21,53,63};
//		shujujiegou.RedBlackTree tree1 = new shujujiegou.RedBlackTree();
//		for(int j : in){
//
//			tree1.add(j, ""+j);
//
//			tree1.order();
//			System.out.println();
//		}
//


        Random r = new Random();
        //Integer[] keysIntegers = {37679,86175,68369,3135,33801,55106,36994,7644,45017,23204,53886,40330,7187,34881,45618,52084,2133,41356,85767,89674,65989,62877,67492,77635,37698,22374,19680,37152,67468,62145,5445,5438,1904,68456,9936,35912,77852,20784,43413,71719,37649,59554,54480,26503,67237,69543,5782,20231,14840,32256,70490,36668,895,3040,16667,69106,47628,79350,49290,58689,70431,83482,60442,65495,77413,16787,55232,14792,36031,83971,71530,68079,37262,87456,29852,72528,56345,2192,66245,41740,78977,25056,15552,27503,48044,16673,56790,61305,85405,22256,65601,16007,61909,10240,39148,65197,48355,32597,47846,28003};
        Integer[] keysIntegers = {46877,43415,34693,69324,59030,40736,439,53564,66448,7057,5412,14830,68564,30068,68835,52706,87953,58688,31244,45793,58285,66396,51961,88538,10739,46881,56761,17290,24443,41211,68179,23511,57063,81756,48264,10297,70889,42605,68049,51750,78162,25970,27624,60984,37061,5992,54386,22972,28586,30621,8249,43018,58703,46684,40408,22140,20281,75204,26688,29982,1672,16293,75768,51328,2664,12614,86577,32106,61028,73701,82647,67821,59285,19372,12499,65634,22520,49100,2461,52017,43261,19289,19535,78528,84427,57666,30805,36694,73810,51867,2609,5803,3944,46921,2907,52318,35717,81673,83109,24994};
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> templist = new ArrayList<Integer>();
        for(int i = 0;i < 1000; i++){
            Integer key = r.nextInt(9000000);
            if(!list.contains(key)){
                list.add(key);
                templist.add(key);
//				System.out.print(key+",");
            }
        }
//		for(Integer k : keysIntegers){
//			list.add(k);
//			templist.add(k);
//		}
        RedBlackTree tree = new RedBlackTree();
        for(Integer key : list){
            tree.add(key, ""+key);
        }
        System.out.println("insert ok");
        for(Integer key : list){
            System.out.println(tree.get(key));
        }
        System.out.println("get ok");

        //tree.order();

        //成功删除:22374
        //成功删除:19680

		/*
		 * 成功删除:12499
			成功删除:65634
			78528cuowu le ...................
		 */

        for(Integer key : list){

            tree.deleteNode(key);
            templist.remove(key);
            for(Integer key1 : templist){
                if(tree.get(key1)==null){
                    System.out.println(key1+"cuowu le ...................");
                    return;
                }
            }
//			tree.order();
        }
        System.out.println("delete ok");
    }



}
